package org.mxp.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RabbitMQUtils {
    /**
     * 获取信道
     * @return
     * @throws Exception
     */
    public static Channel getChannel() throws Exception {
        // 创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        // 设置工厂IP，连接RabbitMQ队列
        factory.setHost("192.168.31.247");
        // 设置用户名
        factory.setUsername("admin");
        // 设置密码
        factory.setPassword("123");
        // 创建连接
        Connection connection = factory.newConnection();
        // 获取信道
        Channel channel = connection.createChannel();
        // 返回信道
        return channel;
    }
}
